<?php use_helper('Javascript','Form')?>

<?php if($contactForm->isNew()):?>
  <?php
    $save_url = 'contact/insertCustomer';
    $reset_url = 'contact/createCustomer';
  ?>
<?php else:?> 
  <?php
    $save_url = 'contact/updateCustomer';
    $reset_url = 'contact/editCustomer';
  ?>
<?php echo link_to('View Receivables','report/statementOfAccount?customer_iden='.$contactForm->getObject()->getIden(),array('target'=>'_customer_soa'));?>
<?php endif;?>
<?php echo form_tag($save_url); ?>
<table>
  <tr>
    <td colspan="2">
      <?php if((! $contactForm->isValid())&&($contactForm->isBound())):?>
        <ul class="error_list"><li>Errors on contact form</ul>
        <?php echo $contactForm->renderGlobalErrors()?>
      <?php endif;?>
      <?php if((! $accountCustomerForm->isValid())&&($accountCustomerForm->isBound())):?>
        <ul class="error_list"><li>Errors on customer form</ul>
        <?php echo $accountCustomerForm->renderGlobalErrors()?>
      <?php endif;?>
    </td>
  </tr>
  <tr>
    <td>
      <div class="infobox1">
        <?php include_partial('contact_fields',array('contactForm'=>$contactForm,))?>
      </div>
    </td>
    <td>
      <div class="infobox1">
        <div class="separator">Customer Info</div>
        <?php include_partial('customer_fields',array('accountCustomerForm'=>$accountCustomerForm,))?>
      </div>
    </td>
  </tr>
</table>
<?php 
  include_partial(
    'save_buttons',
    array(
      'save_url'=>$save_url,
      'delete_url'=>'contact/deleteCustomer',
      'reset_url'=>$reset_url,
      'form_type'=>'customer',
      'list_name'=>$contactForm->getObject()->getListName(),
      'new'=>$contactForm->isNew(),
      'update'=>'contactBox',
      'contact_row'=>'row_contact_'.$iden,
      'update_url'=>'contact/getCustomerColumn?iden='.$iden,
    )
  )
?>
</form>

<?php if($sf_params->get('dialog_mode')):?>
  <div id="divContactDialogButton" style="text-align:center;padding-top:5px;">
    <?php if($sf_params->get('dialog_mode')==='invoice'):?>
      <?php
        echo
          button_to_remote(
            'Invoice',
            array(
              'url'=>'invoice/create?contact_iden='.$contactForm->getObject()->getIden(),
              'update'=>sfConfig::get('app_windows_main_id'),
              'loading'=>"$('indicator').show();",
              'complete'=>"$('indicator').hide();".
                 "Element.show('divInvoiceDrSearchBox');".
                 "Element.show('divInvoiceDrMain');".
                 "Element.hide('divShowSearchInvoice');".
                 "Element.hide('divInvoiceDrPrompt');".
                 "Element.hide('divInvoiceDrSearchGrid');".
                 "Element.show('divInvoiceDr');",
            )
          );
      ?>
    <?php elseif($sf_params->get('dialog_mode')==='payment'):?>
      <?php
        echo
          button_to_remote(
            'Payment',
            array(
              'url'=>'payment/create?contact_iden='.$contactForm->getObject()->getIden(),
              'update'=>sfConfig::get('app_windows_main_id'),
              'loading'=>"$('indicator').show();",
              'complete'=>"$('indicator').hide();",
            )
          );
      ?>
    <?php elseif($sf_params->get('dialog_mode')==='debit_memo'):?>
      <?php
        echo
          button_to_remote(
            'Debit Memo',
            array(
              'url'=>'debitMemo/create?contact_iden='.$contactForm->getObject()->getIden(),
              'update'=>sfConfig::get('app_windows_main_id'),
              'loading'=>"$('indicator').show();",
              'complete'=>"$('indicator').hide();",
            )
          );
      ?>
    <?php elseif($sf_params->get('dialog_mode')==='credit_memo'):?>
      <?php
        echo
          button_to_remote(
            'Credit Memo',
            array(
              'url'=>'creditMemo/create?contact_iden='.$contactForm->getObject()->getIden(),
              'update'=>sfConfig::get('app_windows_main_id'),
              'loading'=>"$('indicator').show();",
              'complete'=>"$('indicator').hide();",
            )
          );
      ?>
    <?php endif;?>
  </div>
<?php endif;?>
